package com.phone.client.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.seventh.common.pojo.R;
import com.phone.client.mapper.CouRecordMapper;
import com.phone.client.poji.entry.CouponHistory;
import com.phone.client.poji.vo.CouRecordVo;
import com.phone.client.service.CouRecordService;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @program: clms-seventh
 * @description: CouRecordService的实现
 * @author: 杨佳琪
 * @create: 2021-07-24 19:30
 **/
@ApiModel(value="优惠券记录service实现", description="优惠券记录service实现")
@Service
public class CouRecordServiceImpl implements CouRecordService {
    @Resource
    private CouRecordMapper couRecordMapper;

    @ApiModelProperty("分页查询")
    @Override
    public R findCouRecordById(Integer currentPage, Integer pageSize, CouRecordVo couRecordVo) {
        Page<CouponHistory> page=new Page<>(currentPage,pageSize);
        QueryWrapper<CouponHistory> wrapper=new QueryWrapper<>();

        if (StringUtils.isNotEmpty(couRecordVo.getUseTime())){
            wrapper.like("use_time",couRecordVo.getUseTime());
        }
        if (StringUtils.isNotEmpty(couRecordVo.getName())){
            wrapper.like("name",couRecordVo.getName());
        }

        IPage<CouponHistory> page1=couRecordMapper.findCouRecordById(page,wrapper);
        return R.ok().put("records",page1.getRecords()).put("total",page1.getTotal());
    }

    @ApiModelProperty("删除")
    @Override
    public R deleteCourec(Integer id) {
        int i=couRecordMapper.deleteById(id);
        return R.ok();
    }
}
